//
//  WBVisitorView.swift
//  weibo
//
//  Created by shizb macbook air on 17/8/3.
//  Copyright © 2017年 YL. All rights reserved.
//

import UIKit

class WBVisitorView: UIView {
    //设置访客视图信息
    var visiterInfo:[String:String]?{
        didSet{
            guard let imageName=visiterInfo?["imageName"],let message=visiterInfo?["message"] else {
                return
            }
            tipLable.text = message
            if imageName=="" {
                return
            }
            iconView.image=UIImage(named: imageName)
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    lazy var iconView:UIImageView=UIImageView(image: UIImage(named:"visitordiscover_feed_image_smallicon"))
    
    lazy var hourseIconView:UIImageView=UIImageView(image: UIImage(named:"visitordiscover_feed_image_house"))
    
    lazy var tipLable:UILabel=UILabel(title: "接口数据你的你说可是你看看", fontSize: 15, Color: UIColor.black)
    
    lazy var registerButton:UIButton=UIButton(title: "注册", fontSize: 16, normalColor: UIColor.orange, highlightColor: UIColor.black, backgroundImageName: "common_button_white_disable")
    
    lazy var loginButton:UIButton=UIButton(title: "登录", fontSize: 16, normalColor: UIColor.orange, highlightColor: UIColor.black, backgroundImageName: "common_button_white_disable")


}

extension WBVisitorView{
    func setupUI() {
        backgroundColor=UIColor.white
        addSubview(iconView)
        addSubview(hourseIconView)
        addSubview(tipLable)
        addSubview(registerButton)
        addSubview(loginButton)
        // 2. 取消 autoresizing
        for v in subviews{
            v.translatesAutoresizingMaskIntoConstraints=false
        }
        //iconView，hourseIconView 图像视图布局
        addConstraint(NSLayoutConstraint(item: iconView,
                                         attribute: .centerX,
                                         relatedBy: .equal,
                                         toItem: self,
                                         attribute: .centerX,
                                         multiplier: 1.0,
                                         constant: 0))
        addConstraint(NSLayoutConstraint(item: iconView,
                                         attribute: .centerY,
                                         relatedBy: .equal,
                                         toItem: self,
                                         attribute: .centerY,
                                         multiplier: 1.0,
                                         constant: -60))
        
        addConstraint(NSLayoutConstraint(item: hourseIconView,
                                         attribute: .centerX,
                                         relatedBy: .equal,
                                         toItem: iconView,
                                         attribute: .centerX,
                                         multiplier: 1.0,
                                         constant: 0))
        addConstraint(NSLayoutConstraint(item: hourseIconView,
                                         attribute: .centerY,
                                         relatedBy: .equal,
                                         toItem: iconView,
                                         attribute: .centerY,
                                         multiplier: 1.0,
                                         constant: 0))
        //lable
        tipLable.textAlignment = .center
        addConstraint(NSLayoutConstraint(item: tipLable,
                                         attribute: .centerX,
                                         relatedBy: .equal,
                                         toItem: iconView,
                                         attribute: .centerX,
                                         multiplier: 1.0,
                                         constant: 0))
        addConstraint(NSLayoutConstraint(item: tipLable,
                                         attribute: .top,
                                         relatedBy: .equal,
                                         toItem: iconView,
                                         attribute: .bottom,
                                         multiplier: 1.0,
                                         constant: 0))
        addConstraint(NSLayoutConstraint(item: tipLable,
                                         attribute: .width,
                                         relatedBy: .equal,
                                         toItem: nil,
                                         attribute: .notAnAttribute,
                                         multiplier: 1.0,
                                         constant: 236))
        //
        
        // 4> 注册按钮
        addConstraint(NSLayoutConstraint(item: registerButton,
                                         attribute: .left,
                                         relatedBy: .equal,
                                         toItem: tipLable,
                                         attribute: .left,
                                         multiplier: 1.0,
                                         constant: 0))
        addConstraint(NSLayoutConstraint(item: registerButton,
                                         attribute: .top,
                                         relatedBy: .equal,
                                         toItem: tipLable,
                                         attribute: .bottom,
                                         multiplier: 1.0,
                                         constant: 20))
        addConstraint(NSLayoutConstraint(item: registerButton,
                                         attribute: .width,
                                         relatedBy: .equal,
                                         toItem: nil,
                                         attribute: .notAnAttribute,
                                         multiplier: 1.0,
                                         constant: 100))
        
        // 5> 登录按钮
        addConstraint(NSLayoutConstraint(item: loginButton,
                                         attribute: .right,
                                         relatedBy: .equal,
                                         toItem: tipLable,
                                         attribute: .right,
                                         multiplier: 1.0,
                                         constant: 0))
        addConstraint(NSLayoutConstraint(item: loginButton,
                                         attribute: .top,
                                         relatedBy: .equal,
                                         toItem: tipLable,
                                         attribute: .bottom,
                                         multiplier: 1.0,
                                         constant: 20))
        addConstraint(NSLayoutConstraint(item: loginButton,
                                         attribute: .width,
                                         relatedBy: .equal,
                                         toItem: registerButton,
                                         attribute: .width,
                                         multiplier: 1.0,
                                         constant: 0))
    }
}











